﻿@using KPIS.GERP.Models.ICM
@using KPIS.GERP.WEB.GIMS.OfficeSuppliesLotService
@model IEnumerable<KPIS.GERP.Models.ICM.OfficeSuppliesLot>
@{
    ViewBag.Title = "ระบบควบคุมและจำหน่ายพัสดุ";
    ViewBag.Descr = "ทะเบียนควบคุมพัสดุ-วัสดุ";
    var ResTypeId = ViewBag.ResTypeId;
    var s1 = new OfficeSuppliesLotServiceClient();
    var s2 = new KPIS.GERP.WEB.GIMS.MasResourceService.MasResourceServiceClient();
}
<style>
    .div1 {
        margin: 0 auto;
    }

    .DataRow {
    }

    .c11 {
        color: rgb(15, 15, 194);
        font-weight: bold;
    }

    .c12 {
        color: black;
        font-weight: normal;
    }


    .black_overlay {
        display: none;
        position: absolute;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        background-color: black;
        z-index: 10;
        -moz-opacity: 0.8;
        opacity: .80;
        filter: alpha(opacity=80);
    }

    .white_content {
        display: none;
        position: absolute;
        top: 25%;
        left: 25%;
        width: 50%;
        height: 50%;
        padding: 16px;
        border: 16px solid orange;
        background-color: white;
        z-index: 9000;
        overflow: auto;
    }
</style>

@using (Html.BeginForm("IndexOfficeSuppliesLot", "ParcelControlAssetList", FormMethod.Post))
{
    <div class="row-fluid">
        <div class="control-group" style="width: 700px; margin-left: 370px;">
            <div class="control-label" style="float: left; width: 120px; margin-right: 0px; margin-top: 4px;">
                เลือกประเภทพัสดุ :
            </div>
            <div class="controls" style="float: left; width: 400px; margin-left: 0px;">
                @Html.DropDownList("ResTypeId", s2.SelectListResourceType(null)
                        , new { id = "lenderType" })
            </div>
            <div class="clear" style="clear: both; width: 0px; height: 0px;"></div>
        </div>

        @Html.ValidationSummary(true, "", new { @class = "alert alert-error" })
        <div class="row-fluid">
            <div class="table-header span12">
                <div class="span10">
                    ทะเบียนควบคุมพัสดุ - วัสดุ
                </div>
            </div>
        </div>

        <table id="table1" class="table table-striped table-bordered table-hover">
            <thead>
                <tr>
                    <th hidden="hidden"></th>
                    <th></th>
                    <th style="width:140px">รหัสวัสดุ</th>S
                    <th>รายการวัสดุ</th>
                    <th style="width:100px">จำนวน</th>
                    <th style="width:110px">หน่วย</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var m in Model)
                {
                    string projectname =
                    (
                        m.ProjectExpense != null && m.ProjectExpense.Project != null ?
                            (m.ProjectExpense.Project.Code + " - " + m.ProjectExpense.Project.Name).Replace("\"", "") : "");

                    projectname = string.IsNullOrWhiteSpace(projectname) ? "-" : projectname;

                    <tr class="DataRow">
                        <td hidden="hidden">@Html.DisplayFor(modelItem => m.OfficeSuppliesLotId)</td>
                        <td>
                            <a href="#"><strong>+</strong></a>
                        </td>
                        <td class="c11">
                            @Html.DisplayFor(modelItem => m.MasResourceItem.Code)
                        </td>
                        <td class="c11">
                            @Html.DisplayFor(modelItem => m.MasResourceItem.Name)
                            <span class="c12">@(projectname != "-" ? " - " + projectname : "")</span>
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => m.Quantity, s1.SuppliesLotQuantity(m.ResItemId ?? 0))
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => m.MasUnit.Name)
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
}

@foreach (var m in Model)
{
    var partialModel = s1.SuppliesLotByResourceItemCode(m.ResItemId ?? 0);
    string divLId = "detail_light_" + m.OfficeSuppliesLotId;
    string js = @"document.getElementById('" + divLId + @"').style.display='none'; document.getElementById('black_overlay').style.display='none';";

    ViewBag.M = m;
    <div id="@divLId" class="white_content">
        @Html.Partial("_EditorPopupOfficeSuppliesLot", partialModel)
        <a href="javascript:void(0)" onclick="@Html.Raw(js)">ปิด</a>
    </div>
}
<div id="black_overlay" class="black_overlay" />

@section scripts
{
    <script type="text/javascript">
        $('#lenderType').change(function () {

            var resType = parseInt($('#lenderType').val());
            if (resType == null) {
            }
            else if (resType == 1) {
                window.location.href = "../ParcelControlAssetList/IndexOfficeSuppliesLot";
            }
            else {
                window.location.href = "../ParcelControlAssetList/IndexAsset";
            }

        });

        $('.DataRow').click(function () {
            var lightId = "detail_light_" + $(this).find("td:first").html();
            var fadeId = "black_overlay";

            document.getElementById(lightId).style.display = 'block';
            document.getElementById(fadeId).style.display = 'block';
        });

        $(function () {
            var oTable1 = $('#table1').dataTable();
            $('[data-rel=tooltip]').tooltip();


        });

    </script>
}